package com.fyx.timedTask;



import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fyx.config.SecondaryMongoConfig;
import com.fyx.entity.*;
import com.fyx.mapper.*;
import com.fyx.modules.system.domain.User;
import com.fyx.modules.system.repository.UserRepository;
import com.fyx.until.DateUtil;
import com.fyx.utils.StringUtils;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import java.util.Date;
import java.util.List;


import static org.springframework.data.mongodb.core.aggregation.Aggregation.match;

/**
 * 广告记录
 */
@Slf4j
@Component(value="ChannelDataTask")
public class ChannelDataTask {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Resource(name = SecondaryMongoConfig.MONGO_TEMPLATE)
    private MongoTemplate secondaryMongoTemplate;

    @Autowired
    private ShareSeatMapper shareSeatMapper;

    public void run(){
//        record();
//        recordChannel();
        getLastMonthData();
        log.info("channel_data：执行完毕=======================");
    }

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private BindPlayerMapper bindPlayerMapper;

    @Autowired
    private SysDictDetailMapper sysDictDetailMapper;

    @Autowired
    private MonthInfoMapper monthInfoMapper;

    public void getLastMonthData() {
        long beginTime = DateUtil.getBeginDayOfLastMonth().getTime()/1000;
        long endTime = DateUtil.getEndDayOfLastMonth().getTime()/1000;

        MonthDataEntity monthDataEntity = new MonthDataEntity();
        monthDataEntity.setTime(DateUtil.getBeginDayOfLastMonth().getTime()/1000);

        //红中麻将充值统计
        Criteria criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time_end").gte(beginTime)
                , Criteria.where("time_end").lt(endTime)
        );
        Aggregation aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        AggregationResults<OrderEntity> ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        List<OrderEntity> list = ar.getMappedResults();
        double totalFee = 0;
        if (list.size()>0){
            OrderEntity OrderEntity = list.get(0);
            totalFee = OrderEntity.getTotalFee();
        }
        monthDataEntity.setAllMoney(totalFee/100);

        //红中麻将苹果充值统计
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time_end").gte(beginTime).lt(endTime)
                ,Criteria.where("os").is("ios")
        );
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setAppleHzmjMoney(totalFee/100);

        //红中麻将安卓充值统计
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time_end").gte(beginTime).lt(endTime)
                ,Criteria.where("os").is("android")
        );
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setAndroidHzmjMoney(totalFee/100);

        //红中麻将电脑端充值统计
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time_end").gte(beginTime).lt(endTime)
                ,Criteria.where("os").is("pc")
        );
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setPcHzmjMoney(totalFee/100);


        //红中麻将QQ充值统计
        //红中麻将QQ_minigame_pay统计
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_qq");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setQqMiniGamePay(totalFee / 100);

        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_7k7k");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setSevenkpay(totalFee / 100);

        //红中麻将iqiyi统计
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_iqiyi");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setIqiyiPay(totalFee / 100);

        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_topon");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setDouyinpay(totalFee / 100);

        //红中麻将QQ_minigame_pay统计
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_meituan$");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setMeituanPay(totalFee / 100);

        //美团红包版
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_meituan_re");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setMeituanRePay(totalFee / 100);

        //微信小游戏充值统计
        criteria = new Criteria();
        String[] wx = {"xunguangpay", "WX_minigame_pay"};
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_wechat");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setWxMiniGamePay(totalFee / 100);

        //彩票充值
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_500caipiao");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setCaipiaopay(totalFee / 100);

        //顺网充值统计
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_swjoy");

        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setSwjoyPay(totalFee / 100);

        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_tvcoocaa");

        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setTvcoocaapay(totalFee / 100);

        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_tvhisense");

        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setTvhisensepay(totalFee / 100);

        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_tvhuan");

        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setTvhuanpay(totalFee / 100);

        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_mmy");

        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setMmypay(totalFee / 100);


        //vivo充值统计
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);

        criteria.and("channel").regex("_vivo$");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setVivoPay(totalFee / 100);


        //vivoad包充值统计
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_vivoad");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setVivoAdPay(totalFee / 100);

        //闪电玩充值
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_sdwh5");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setSdwpay(totalFee / 100);

        //2345充值
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_game2345");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setA2345pay(totalFee / 100);

        //迅雷充值
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_xunlei");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setXunleipay(totalFee / 100);

        //百度充值
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_baidu");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setBaidupay(totalFee / 100);

        //小米充值
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_xiaomi");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setMipay(totalFee / 100);

        //苹果渠道充值
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_apple");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setApplepay(totalFee / 100);

        //华为充值
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("^(?!h5).*_huawei");

        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setHuaweipay(totalFee / 100);

        //华为h5充值
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("h5.*_huawei");

        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setHuaweih5pay(totalFee / 100);

        //红中麻将oppoH5统计
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("h5.*_oppo");

        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setOppoPay(totalFee / 100);

        //红中麻将oppoMb统计
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("^(?!h5).*_oppo");

        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setOppoMbPay(totalFee / 100);

        //红中麻将jd统计
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_jd");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setJdPay(totalFee / 100);

        //红中麻将自营统计
        criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        criteria.and("channel").regex("_official");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        list = ar.getMappedResults();
        totalFee = 0;
        if (list.size() > 0) {
            OrderEntity orderEntity = list.get(0);
            totalFee = orderEntity.getTotalFee();
        }
        monthDataEntity.setOfficial(totalFee / 100);

        //总的充值统计
//        monthDataEntity.setAllMoney(monthDataEntity.getAppleHzmjMoney()+monthDataEntity.getAndroidHzmjMoney());

        //红中麻将月活跃
        criteria = new Criteria();
        criteria.andOperator(Criteria.where("last_time").gte(beginTime).lt(endTime));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        int count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setMonthActivity(count);

        //红中麻将月新增用户
        criteria = new Criteria();
        criteria.andOperator(Criteria.where("reg_time").gte(beginTime).lt(endTime));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setNewUserCount(count);

        //红中麻将苹果月新增用户
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("reg_time").gte(beginTime).lt(endTime)
                ,Criteria.where("os").is("ios")
        );
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setIosnewUser(count);

        //红中麻将安卓月新增用户
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("reg_time").gte(beginTime).lt(endTime)
                ,Criteria.where("os").is("android")
        );
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setAndroidnewUser(count);

        //红中麻将pc月新增用户
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("reg_time").gte(beginTime).lt(endTime)
                ,Criteria.where("os").is("pc")
        );
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setPcUserCount(count);

        //穿山甲
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time").gte(beginTime)
                , Criteria.where("time").lt(endTime)
        );
        criteria.orOperator(Criteria.where("channel").is("total"),Criteria.where("channel").exists(false));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("pangolin").as("pangolin")
        );
        AggregationResults<DayDataEntity> ar1 = mongoTemplate.aggregate(aggregation, "day_data", DayDataEntity.class);
        List<DayDataEntity> list1 = ar1.getMappedResults();
        double pangolin=0;
        if (list1.size()>0){
            DayDataEntity dataEntity = list1.get(0);
            pangolin = dataEntity.getPangolin();
        }
        monthDataEntity.setPangolin(pangolin);

        //优量汇
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time").gte(beginTime)
                , Criteria.where("time").lt(endTime)
        );
        criteria.orOperator(Criteria.where("channel").is("total"),Criteria.where("channel").exists(false));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("youlianghui").as("youlianghui")
        );
        ar1 = mongoTemplate.aggregate(aggregation, "day_data", DayDataEntity.class);
        list1 = ar1.getMappedResults();
        double youlianghui=0;
        if (list1.size()>0){
            DayDataEntity dataEntity = list1.get(0);
            youlianghui = dataEntity.getYoulianghui();
        }
        monthDataEntity.setYoulianghui(youlianghui);

        //vivo
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time").gte(beginTime)
                , Criteria.where("time").lt(endTime)
        );
        criteria.orOperator(Criteria.where("channel").is("total"),Criteria.where("channel").exists(false));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("vivo").as("vivo")
        );
        ar1 = mongoTemplate.aggregate(aggregation, "day_data", DayDataEntity.class);
        list1 = ar1.getMappedResults();
        double vivo=0;
        if (list1.size()>0){
            DayDataEntity dataEntity = list1.get(0);
            vivo = dataEntity.getVivo();
        }
        monthDataEntity.setVivo(vivo);

        //vivoAd
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time").gte(beginTime)
                , Criteria.where("time").lt(endTime)
        );
        criteria.orOperator(Criteria.where("channel").is("total"),Criteria.where("channel").exists(false));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("vivoAd").as("vivoAd")
        );
        ar1 = mongoTemplate.aggregate(aggregation, "day_data", DayDataEntity.class);
        list1 = ar1.getMappedResults();
        vivo=0;
        if (list1.size()>0){
            DayDataEntity dataEntity = list1.get(0);
            vivo = dataEntity.getVivoAd();
        }
        monthDataEntity.setVivoAd(vivo);

        //mi
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time").gte(beginTime)
                , Criteria.where("time").lt(endTime)
        );
        criteria.orOperator(Criteria.where("channel").is("total"),Criteria.where("channel").exists(false));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("mi").as("mi")
        );
        ar1 = mongoTemplate.aggregate(aggregation, "day_data", DayDataEntity.class);
        list1 = ar1.getMappedResults();
        vivo=0;
        if (list1.size()>0){
            vivo = list1.get(0).getMi();

        }
        monthDataEntity.setMi(vivo);

        //huawei
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time").gte(beginTime)
                , Criteria.where("time").lt(endTime)
        );
        criteria.orOperator(Criteria.where("channel").is("total"),Criteria.where("channel").exists(false));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("huawei").as("huawei")
        );
        ar1 = mongoTemplate.aggregate(aggregation, "day_data", DayDataEntity.class);
        list1 = ar1.getMappedResults();
        vivo=0;
        if (list1.size()>0){

            vivo = list1.get(0).getHuawei();
        }
        monthDataEntity.setHuawei(vivo);

        //iOS
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time").gte(beginTime)
                , Criteria.where("time").lt(endTime)
        );
        criteria.orOperator(Criteria.where("channel").is("total"),Criteria.where("channel").exists(false));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("iOS").as("iOS")
        );
        ar1 = mongoTemplate.aggregate(aggregation, "day_data", DayDataEntity.class);
        list1 = ar1.getMappedResults();
        vivo=0;
        if (list1.size()>0){

            vivo = list1.get(0).getIOS();
        }
        monthDataEntity.setIOS(vivo);

        //oppo
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time").gte(beginTime)
                , Criteria.where("time").lt(endTime)
        );
        criteria.orOperator(Criteria.where("channel").is("total"),Criteria.where("channel").exists(false));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("oppo").as("oppo").sum("mmy").as("mmy")
        );
        ar1 = mongoTemplate.aggregate(aggregation, "day_data", DayDataEntity.class);
        list1 = ar1.getMappedResults();
        vivo=0;
        if (list1.size()>0){
            vivo = list1.get(0).getOppo();
            monthDataEntity.setMmy(list1.get(0).getMmy());
        }
        monthDataEntity.setOppo(vivo);


        //oppoH5
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time").gte(beginTime)
                , Criteria.where("time").lt(endTime)
        );
        criteria.orOperator(Criteria.where("channel").is("total"),Criteria.where("channel").exists(false));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("oppoH5").as("oppoH5").sum("sevenk").as("sevenk").sum("iqiyiH5").as("iqiyiH5")
        );
        ar1 = mongoTemplate.aggregate(aggregation, "day_data", DayDataEntity.class);
        list1 = ar1.getMappedResults();
        vivo=0;
        if (list1.size()>0){
            vivo = list1.get(0).getOppoH5();
            monthDataEntity.setSevenk(list1.get(0).getSevenk());
            monthDataEntity.setIqiyiH5(list1.get(0).getIqiyiH5());
        }
        monthDataEntity.setOppoH5(vivo);

        //oppoH5
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time").gte(beginTime)
                , Criteria.where("time").lt(endTime)
        );
        criteria.orOperator(Criteria.where("channel").is("total"),Criteria.where("channel").exists(false));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("chuanshanjia").as("chuanshanjia").sum("douyin").as("douyin")
        );
        ar1 = mongoTemplate.aggregate(aggregation, "day_data", DayDataEntity.class);
        list1 = ar1.getMappedResults();
        vivo=0;
        monthDataEntity.setDouyin(0.0);
        if (list1.size()>0){
            vivo = list1.get(0).getChuanshanjia();
            monthDataEntity.setDouyin(list1.get(0).getDouyin());
        }
        monthDataEntity.setChuanshanjia(vivo);
        //  System.out.println(monthDataEntity);
        mongoTemplate.remove(new Query(Criteria.where("time").is(monthDataEntity.getTime())), MonthDataEntity.class);
        mongoTemplate.insert(monthDataEntity);
    }

    public void month(){
        Long time = DateUtil.getBeginDayOfMonth().getTime()/1000;
        Long nowTime=new Date().getTime()/1000;
        Long endTime=DateUtil.getEndDayOfMonth().getTime()/1000;
        if(time==nowTime){
            time=DateUtil.getBeginDayOfLastMonth().getTime()/1000;
            endTime=DateUtil.getEndDayOfLastMonth().getTime()/1000;
        }
        MonthInfo monthInfo=new MonthInfo();
        monthInfo.setTime(time.intValue());
        Criteria criteria = new Criteria();
        criteria.and("reg_time").gte(time).lte(endTime);
       // criteria.and("channel").is("total");//.is(user.getUsername());
        Aggregation aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group("id").count().as("v4"),
                Aggregation.group().sum("v4").as("v4")
        );
        AggregationResults<StaticeEntity>  ar = mongoTemplate.aggregate(aggregation, "user", StaticeEntity.class);
        List<StaticeEntity> list1 = ar.getMappedResults();
        if(list1.size()>0){
            monthInfo.setActivePerson(list1.get(0).getV4());
        }
         criteria.and("all_fee").gt(0);
         aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group("id").count().as("v4"),
                Aggregation.group().sum("v4").as("v4")
        );
         ar = mongoTemplate.aggregate(aggregation, "user", StaticeEntity.class);
        list1 = ar.getMappedResults();
        if(list1.size()>0){
            monthInfo.setPayPerson(list1.get(0).getV4());
        }

        QueryWrapper<MonthInfo> wrapper=new QueryWrapper<>();
        wrapper.eq("time",time);
        MonthInfo monthInfo1=monthInfoMapper.selectOne(wrapper);
        if(monthInfo1==null){
            monthInfoMapper.insert(monthInfo);
        }else {
            monthInfoMapper.update(monthInfo,wrapper);
        }
    }

    public void recordChannel(){
        long time = DateUtil.getDayBegin().getTime()/1000;
        long nowTime=new Date().getTime()/1000;
        if(time==nowTime){
            time=DateUtil.getBeginDayOfYesterday().getTime()/1000;
        }
        long endTime=DateUtil.getDayEnd().getTime()/1000;
            Criteria criteria = new Criteria();
            criteria.and("unix_time").gte(time).lte(endTime);
            criteria.and("invite_id").exists(true);//.is(user.getUsername());
            Aggregation aggregation = Aggregation.newAggregation(
                    Aggregation.match(criteria),
                    Aggregation.group("invite_id").count().as("v4").first("invite_id").as("v6").last("channel").as("v7")
            );
            AggregationResults<StaticeEntity>  ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", StaticeEntity.class);
            List<StaticeEntity> list1 = ar.getMappedResults();
            if(list1.size()>0){
                for(StaticeEntity staticeEntity:list1){
                    QueryWrapper<BindPlayer> wrapper1 =new QueryWrapper<>();
                    wrapper1.eq("user_id",staticeEntity.getV6());
                    BindPlayer old=bindPlayerMapper.selectOne(wrapper1);
                    if(old==null&&!staticeEntity.getV6().equals("null")) {
                        BindPlayer bindPlayer1 = new BindPlayer();
                        bindPlayer1.setUserId(staticeEntity.getV6());
                        bindPlayer1.setBindNum(0l);
                        bindPlayer1.setBindNew(staticeEntity.getV4());
                        bindPlayer1.setChannel(staticeEntity.getV7());
                        bindPlayer1.setTime((int)time);
                        bindPlayerMapper.insert(bindPlayer1);
                    }else if(!staticeEntity.getV6().equals("null")&&old!=null){
                        if(time>old.getTime()){
                            old.setBindNum(old.getBindNum()+old.getBindNew());
                            old.setTime((int)time);
                            old.setBindNew(staticeEntity.getV4());
                        }else{
                            old.setTime((int)time);
                            old.setBindNew(staticeEntity.getV4());
                        }
                        bindPlayerMapper.update(old,wrapper1);
                    }

                }
            }
    }

     public  void  record(){
     long time = DateUtil.getDayBegin().getTime()/1000;
     long nowTime=new Date().getTime()/1000;
     if(time==nowTime){
         time=DateUtil.getBeginDayOfYesterday().getTime()/1000;
     }
     long endTime=DateUtil.getDayEnd().getTime()/1000;
     QueryWrapper<ShareSeat> wrapper=new QueryWrapper<>();
     wrapper.eq("time",time);
     shareSeatMapper.delete(wrapper);
     QueryWrapper<SysDictDetail> wrapper1=new QueryWrapper<>();
     wrapper1.eq("dict_id",16);
     wrapper1.le("dict_sort",988);
     wrapper1.orderByDesc("dict_sort");
     SysDictDetail sysDictDetail2=new SysDictDetail();
     sysDictDetail2.setValue("total");
     List<SysDictDetail> list1=sysDictDetailMapper.selectList(wrapper1);
     list1.add(sysDictDetail2);
     if(list1.size()>0) {
         for (SysDictDetail sysDictDetail : list1) {
             ShareSeat shareSeat=new ShareSeat();
             shareSeat.setChannel(sysDictDetail.getValue());
             shareSeat.setTime((int)time);
             Criteria criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("1");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             Aggregation aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             AggregationResults<TaskEntity> ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             List<TaskEntity> list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("2");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber1(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("3");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber2(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("4");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber3(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("5");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber4(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("6");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber5(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("7");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber6(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("8");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber7(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("9");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber8(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("10");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber9(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("11");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber10(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("12");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber11(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("13");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber12(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("14");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber13(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("15");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber14(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("16");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber15(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("17");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber16(list.get(0).getNum());
             }
             criteria=new Criteria();
             criteria.and("unix_time").gte(time).lte(endTime);
             criteria.and("invite_extra").is("18");
             if(!sysDictDetail.getValue().equals("total")) {
                 criteria.and("channel").is(sysDictDetail.getValue());
             }
             aggregation = Aggregation.newAggregation(
                     Aggregation.match(criteria),
                     Aggregation.group("id").count().as("num"),
                     Aggregation.group().sum("num").as("num")
             );
             ar = secondaryMongoTemplate.aggregate(aggregation, "register_rec", TaskEntity.class);
             list = ar.getMappedResults();
             if (list.size() > 0) {
                 shareSeat.setNumber17(list.get(0).getNum());
             }
             shareSeatMapper.insert(shareSeat);
         }
      }
     }



}
